/*
 * @Author: MarsLay 331412466@qq.com
 * @Date: 2023-06-19 09:50:26
 * @LastEditors: MarsLay 331412466@qq.com
 * @LastEditTime: 2023-06-19 12:01:49
 * @FilePath: \nanhu-manage-pc\src\utils\util.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Message } from "element-ui";
export const utils = {
  isEmpty: (v) => {
    let bool = false;
    switch (typeof v) {
      case "string":
        bool = v === "";
        break;
      case "number":
        bool = v <= 0;
        break;
      case "object":
        if (v && v.length == 0) {
          bool = true;
        } else if (v && v.length > 0) {
          bool = v.map((x) => x.mobile === "" || x.username === "")[0];
        }
        break;
    }
    return bool;
  },
  verify: (form, rules,) => {
    // 非空条件验证
    for (let [k, v] of Object.entries(rules)) {
      if (v.required && utils.isEmpty(form[k])) {
        Message.error(v.message);
        return;
      }

      // 条件验证
      if (v.required && rules[k].reg && !form[k].match(rules[k].reg)) {
        Message.error(v.message);
        return;
      }
    }

    return true;
  }
}


